import {ValidateMsg} from '../share-data';

export class PageConfig {
  constructor() {}
  title: string;
  controller: string;
  property: any;
  fields= [];
  formErrors: {};
  formErrorKeys= [];
  notInFormErrorKey= [];
  vMessages= {} ;
  dialogs= {};
}

/**
 *  表单验证
 */
export class FormValidate {
  constructor(_cols?: any[]) {
    this.columns = _cols;
    this.columns.forEach(item => {
      if ( item.validates ) {
        this.formErrorKeys.push(item.field);
        this.formError[item.field] = '';
        this.vMessages[item.field] = {};
        // this.vMessages[item.field] = [];
        Object.keys(item.validates).forEach(val => {
          this.vMessages[item.field][val] = `[${[item.label]}] ${ item.validates[val] ? item.validates[val] : ValidateMsg[val]}`;
        });
        // item.validates.forEach(val => {
        //   this.vMessages[item.field][val] = `[${[item.label]}] ${ValidateMsg[val]}`;
        // });
      }
      if (item.outForm) {  // 不在form表单中的控件,即自己写的组件
        this.outFormErrorKey.push(item);
      }
    });
  }
  columns: any[] = [];
  formError: any = {};
  formErrorKeys = [];
  outFormErrorKey = [];
  vMessages = {};
  get column(){
    let res = {};
    this.columns.forEach(item => {
      res[item.field] = item;
    });
    return res;
  }
}
